package cn.jiyun.dao;

import cn.jiyun.pojo.CheckGroup;
import cn.jiyun.pojo.CheckItem;
import cn.jiyun.pojo.HotSetmeal;
import cn.jiyun.pojo.Setmeal;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetmealDao {
    Page<Setmeal> findList(String queryString);

    void add(Setmeal setmeal);

    @Insert("INSERT INTO `health`.`t_setmeal_checkgroup`(`setmeal_id`, `checkgroup_id`) VALUES (#{sid}, #{gid})")
    void addSG(@Param("gid") Integer checkgroupId, @Param("sid") Integer id);

    @Select("select checkitem_id from t_checkgroup_checkitem where checkgroup_id=#{id}")
    List<Integer> findCheckItemIdsByGid(Integer id);

    void edit(Setmeal setmeal);

    @Delete("delete from t_checkgroup_checkitem where checkgroup_id=#{id}")
    void delGIByGid(Integer id);

    @Select("select * from t_setmeal")
    List<Setmeal> findAll();

    @Select("select * from t_setmeal where id = #{id}")
    Setmeal findById(Integer id);

    @Select("SELECT g.* FROM t_setmeal_checkgroup sg , t_checkgroup g WHERE sg.checkgroup_id = g.id AND sg.setmeal_id = #{id}")
    List<CheckGroup> findCheckGroupsBySid(Integer id);

    @Select("SELECT i.* FROM t_checkgroup_checkitem gi , t_checkitem i WHERE gi.checkitem_id = i.id AND gi.checkgroup_id = #{id}")
    List<CheckItem> findItemsByGid(Integer id);

    @Select("SELECT s.`name`,COUNT(*) as setmeal_count, " +
            "COUNT(*) /(SELECT COUNT(*) FROM t_order) as proportion,s.remark " +
            "FROM t_order o , t_setmeal  s WHERE o.setmeal_id = s.id  GROUP BY s.id  order by COUNT(*) DESC LIMIT 2")
    List<HotSetmeal> getHotSetmealList();
}
